package com.sniff.atp.modules.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sniff.atp.modules.test.mapper.MobilePhoneLogMapper;
import com.sniff.atp.modules.test.mapper.PublishPlanMapper;
import com.sniff.atp.modules.test.model.DemandReport;
import com.sniff.atp.modules.test.model.MobilePhoneLog;
import com.sniff.atp.modules.test.model.PublishPlan;
import com.sniff.atp.modules.test.service.MobilePhoneLogService;
import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author macro
 * @since 2023-11-28
 */
@Service
public class MobilePhoneLogServiceImpl extends ServiceImpl<MobilePhoneLogMapper, MobilePhoneLog> implements MobilePhoneLogService {

    @Autowired
    private MobilePhoneLogMapper mobilePhoneLogMapper;

    @Override
    public boolean create(MobilePhoneLog mobilePhoneLog) {
        mobilePhoneLog.setCreateTime(new Date());
        mobilePhoneLog.setUpdateTime(new Date());
        return save(mobilePhoneLog);
    }

    @Override
    public boolean update(Long id, MobilePhoneLog mobilePhoneLog) {
        mobilePhoneLog.setMobilePhoneLogId(id);
        mobilePhoneLog.setUpdateTime(new Date());
        return updateById(mobilePhoneLog);
    }

    @Override
    public Page<MobilePhoneLog> list(MobilePhoneLog mobilePhoneLog, Integer pageSize, Integer pageNum) {

        Page<MobilePhoneLog> page = new Page<>(pageNum,pageSize);
        QueryWrapper<MobilePhoneLog> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(MobilePhoneLog::getMobileId,mobilePhoneLog.getMobileId())
//                .ge(publishPlan.getStartTime() != null,PublishPlan::getCreateTime,publishPlan.getStartTime())
//                .le(publishPlan.getEndTime() != null,PublishPlan::getCreateTime,publishPlan.getEndTime())
                .orderByDesc(MobilePhoneLog::getCreateTime);
        return page(page, wrapper);
    }
}
